import 'package:flutter/material.dart';
import 'package:flutter_project/common/update/update_version_page.dart';
import 'package:flutter_project/config/common_string_config.dart';


class UpdateVersionUtils {
  UpdateVersionUtils(_);

  static bool checkUpdateVersion(BuildContext context,
      {Function? refuseAction}) {
    String latestVersion ='1.0.1';
    latestVersion = latestVersion.replaceAll('.', '');
    String oldVersion = CommonStringConfig.appVersion.replaceAll('.', '');
    if (int.parse(oldVersion) < int.parse(latestVersion)) {
      UpdateVersionUtils.showUpdateView(
          context,{'update':1,'content':'1.优化线上已知问题'},
          refuseAction: refuseAction);
      return true;
    }
    return false;
  }

  static showUpdateView(BuildContext context, Map resMap,
      {Function? refuseAction}) {
    int update = resMap['update'];
    showDialog(
      context: context,
      barrierDismissible: update == 1 ? true : false,
      builder: (BuildContext context) {
        return UpdateVersionPage(
          content: resMap['content'],
          update: update,
          refuseAction: refuseAction,
        );
      },
    );
  }
}
